package com.cakebackoffice.clientsoap;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.cakebackoffice.R;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Marjorie
 * Date: 22/03/12
 * Time: 22:10
 * To change this template use File | Settings | File Templates.
 */
public class TestAdapter extends ArrayAdapter<SoapTest> {
    private int resource;

    public TestAdapter(Context context, int textViewResourceId, List<SoapTest> soapTests) {
        super(context, textViewResourceId, soapTests);
        this.resource = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LinearLayout testView;
        // Récuperer l'order courant
        SoapTest test = getItem(position);

        // Inflate the catalog_detail_product
        if (convertView == null) {
            testView = new LinearLayout(getContext());
            String inflater = Context.LAYOUT_INFLATER_SERVICE;
            LayoutInflater vi = (LayoutInflater) getContext().getSystemService(inflater);
            vi.inflate(resource, testView, true);
        } else {
            testView = (LinearLayout) convertView;
        }

        // Récupérer les View des orderView
        TextView Name = (TextView) testView.findViewById(R.id.testName);
        TextView Value = (TextView) testView.findViewById(R.id.resultValue);
        TextView Result = (TextView) testView.findViewById(R.id.resultString);
        try {
            // les rempliiiir !!
            int color = Color.RED;
            if (test.isSuccess == true) {
                color = Color.GREEN;
            }
            Name.setText(test.Name);
            Value.setText(test.isSuccess.toString());
            Result.setText(test.result.toString());
            Name.setTextColor(color);
            Value.setTextColor(color);
            Result.setTextColor(color);

        } catch (Exception e) {

        }

        return (testView);
    }
}
